const china = require('../map/chinaThree.json')

let optionsLicenseAddress = []
function resetChina(list, arr, n) {
  list.forEach((item, index) => {
    let jtem = { text: item.name ? item.name : item, value: n + index + '' }
    arr.push(jtem)
    if (item.children && item.children.length > 0) {
      jtem.children = []
      resetChina(item.children, jtem.children, jtem.value)
    }
  })
}
resetChina(china, optionsLicenseAddress, 0)
console.log(optionsLicenseAddress)

export function getCityList(allCityList, paramsCityList, getArr) {
  const [, shengName, shiName = ''] = paramsCityList
  const cityLv = paramsCityList.length

  allCityList.forEach(item => {
    if (item.text.includes(shengName)) {
      if (item.children) {
        item.children.forEach(childItem => {
          if (cityLv === 2) {
            getArr.push(childItem.text)
          }
          if (cityLv === 3 && childItem.text.includes(shiName)) {
            childItem.children.forEach(t3childItem => {
              getArr.push(t3childItem.text)
            })
          }
        })
      }
    } else {
      if (item.children) {
        getCityList(item.children, paramsCityList, getArr)
      }
    }
  })
  return getArr
}
console.log(getCityList(optionsLicenseAddress, ['中国', '浙江省'], []))
